/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import controle.ControladorCadastro;
import enumerations.Especie;
import enumerations.Porte;
import exceptions.CadastroException;
import javax.swing.JOptionPane;
import modelo.PorteFaixa;

/**
 *
 * @author Slrx
 */
public class TelaCadastroPorteFaixa extends javax.swing.JFrame {

    /**
     * Creates new form TelaCadastroPorteFaixa
     */
    public TelaCadastroPorteFaixa() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextFieldPorteFaixaAlturaInicial = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldPorteFaixaAlturaFinal = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldPorteFaixaCompInicial = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPorteFaixaCompFinal = new javax.swing.JTextField();
        jComboBoxPorteFaixaEspecie = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxPorteFaixaPorte = new javax.swing.JComboBox();
        jButtonCadastroPorteFaixa = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de faixa de porte");

        jLabel1.setText("Altura inicial:");

        jTextFieldPorteFaixaAlturaInicial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPorteFaixaAlturaInicialActionPerformed(evt);
            }
        });

        jLabel2.setText("Altura final:");

        jTextFieldPorteFaixaAlturaFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPorteFaixaAlturaFinalActionPerformed(evt);
            }
        });

        jLabel3.setText("Comprimento inicial:");

        jLabel4.setText("Comprimento final:");

        jTextFieldPorteFaixaCompFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPorteFaixaCompFinalActionPerformed(evt);
            }
        });

        jComboBoxPorteFaixaEspecie.setModel(new javax.swing.DefaultComboBoxModel(Especie.values()));

        jLabel5.setText("Espécie:");

        jLabel6.setText("Porte:");

        jComboBoxPorteFaixaPorte.setModel(new javax.swing.DefaultComboBoxModel(Porte.values()));

        jButtonCadastroPorteFaixa.setText("Salvar");
        jButtonCadastroPorteFaixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCadastroPorteFaixaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(51, 51, 51)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addGap(18, 18, 18)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jTextFieldPorteFaixaCompInicial, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
                                        .addComponent(jTextFieldPorteFaixaAlturaFinal)
                                        .addComponent(jTextFieldPorteFaixaAlturaInicial)
                                        .addComponent(jTextFieldPorteFaixaCompFinal)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(81, 81, 81)
                                    .addComponent(jLabel5)
                                    .addGap(18, 18, 18)
                                    .addComponent(jComboBoxPorteFaixaEspecie, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(147, 147, 147)
                            .addComponent(jLabel6)
                            .addGap(18, 18, 18)
                            .addComponent(jComboBoxPorteFaixaPorte, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(170, 170, 170)
                        .addComponent(jButtonCadastroPorteFaixa)))
                .addContainerGap(134, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldPorteFaixaAlturaInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldPorteFaixaAlturaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldPorteFaixaCompInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldPorteFaixaCompFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jComboBoxPorteFaixaEspecie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jComboBoxPorteFaixaPorte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButtonCadastroPorteFaixa)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldPorteFaixaAlturaFinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldPorteFaixaAlturaFinalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldPorteFaixaAlturaFinalActionPerformed

    private void jButtonCadastroPorteFaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastroPorteFaixaActionPerformed
        try {
            Double alturaInicial = Double.valueOf(jTextFieldPorteFaixaAlturaInicial.getText());
            Double alturaFinal = Double.valueOf(jTextFieldPorteFaixaAlturaFinal.getText());
            Double comprimentoInicial = Double.valueOf(jTextFieldPorteFaixaCompInicial.getText());
            Double comprimentoFinal = Double.valueOf(jTextFieldPorteFaixaCompFinal.getText());
            Especie especie = Especie.values()[jComboBoxPorteFaixaEspecie.getSelectedIndex()];
            Porte porte = Porte.values()[jComboBoxPorteFaixaPorte.getSelectedIndex()];
            PorteFaixa portefaixa = new PorteFaixa(alturaInicial, alturaFinal, comprimentoInicial, comprimentoFinal, especie, porte);

            ControladorCadastro.cadastrar(portefaixa);
            
            JOptionPane.showMessageDialog(this, "Faixa de porte para " + portefaixa + " cadastrada com sucesso.");
        } catch (CadastroException e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Preencha os campos com os tipos de dados adequados.");
        }
    }//GEN-LAST:event_jButtonCadastroPorteFaixaActionPerformed

    private void jTextFieldPorteFaixaAlturaInicialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldPorteFaixaAlturaInicialActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldPorteFaixaAlturaInicialActionPerformed

    private void jTextFieldPorteFaixaCompFinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldPorteFaixaCompFinalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldPorteFaixaCompFinalActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroPorteFaixa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroPorteFaixa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroPorteFaixa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroPorteFaixa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaCadastroPorteFaixa().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCadastroPorteFaixa;
    private javax.swing.JComboBox jComboBoxPorteFaixaEspecie;
    private javax.swing.JComboBox jComboBoxPorteFaixaPorte;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField jTextFieldPorteFaixaAlturaFinal;
    private javax.swing.JTextField jTextFieldPorteFaixaAlturaInicial;
    private javax.swing.JTextField jTextFieldPorteFaixaCompFinal;
    private javax.swing.JTextField jTextFieldPorteFaixaCompInicial;
    // End of variables declaration//GEN-END:variables
}
